<script setup lang='ts'>
  import { nextTick, reactive, ref } from 'vue';
  import { storeToRefs } from 'pinia';
  import { userStore } from '@/pinia/modules/user';
import { numberApi } from '@/api/controller';
import { Toastloading } from '@/utils/public';
  const { oss_url } = storeToRefs(userStore())
  const action = reactive({
    dialogFormVisible:false,
  })
  const form = reactive({
    card_name:'',
    card_id:'',
    img:[]
  })
  const openDialog = async(query:any = {})=> {
    const { user_id=0, active_certify_model,} = query;
    if(active_certify_model) {
      const { card_id='', card_name='', img=[] } = active_certify_model
      Object.assign(form,{
        card_name,
        card_id,
        img
      })
    } else {
      const loading = Toastloading()
      const res = await numberApi.getActiveCertifyInfo(user_id)
      const { idcard_name='', idcard_number='' } = res.data || {}
      loading.close()
      Object.assign(form,{
        card_name:idcard_name,
        card_id:idcard_number,
      })
    }
    action.dialogFormVisible = true
  }
  const closeDialog = ()=>{
    action.dialogFormVisible = false
  }
  defineExpose({
    openDialog
  })
</script>

<template>
  <div>
    <el-dialog
    top="5vh"
    class="xm-dialog"
    v-model="action.dialogFormVisible"
    :close-on-click-modal="false"
    :show-close="false"
    :close-on-press-escape="false"
    destroy-on-close
    title="认证信息">
      <el-form ref="uuidForm" :model="form" label-width="100px">
        <el-form-item label="姓名">
          <el-input :readonly="true" v-model="form.card_name" />
        </el-form-item>
        <el-form-item label="身份证号">
          <el-input :readonly="true" v-model="form.card_id" />
        </el-form-item>
        <el-form-item v-if="form.img.length > 0" label="凭证">
          <div
            v-for="(url, key) of form.img"
            :key="key"
            class="block"
          >
            <a :href="oss_url + url" :alt="url" title="点击下载">{{ url }}</a>
          </div>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="closeDialog">取 消</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<style lang="scss" scoped >
  .xm-dialog{
    .el-input {
        width: calc($inputWidth);
    }
}
</style>